#pragma once
#include<iostream>
#include<stdio.h>
#include<string>
#include<functional>

using  func_t = std::function<int(int,int,char)>;

class calTask
{
public:
    calTask()
    {}
    calTask(int x,int y,char op,func_t func)
    :_x(x),_y(y),_op(op),_callblack(func)
    {}
    std::string operator()()
    {
        int result = _callblack(_x,_y,_op);
        char buffer[1024];
        snprintf(buffer,sizeof(buffer),"%d %c %d = %d",_x,_op,_y,result);
        return buffer;
    }
    std::string toTaskString()
    {
        char buffer[1024];
        snprintf(buffer,sizeof(buffer),"%d %c %d = ?",_x,_op,_y);
        return buffer;
    }
    // std
    ~calTask()
    {}
private:
    int _x;
    int _y;
    char _op;
    func_t _callblack;
};

class saveTask
{
public:
    typedef std::function<void(std::string)> func_t;
public:
    saveTask()
    {}
    saveTask(std::string message,func_t func)
    :_message(message),_callblack(func)
    {}
    void operator()()
    {
        _callblack(_message);
    }
    ~saveTask()
    {}
private:
    std::string _message;
    func_t _callblack;
};

void Save(const std::string& message)
{
    const std::string target = "./log.txt";
    FILE* fd = fopen(target.c_str(),"a+");
    if(!fd)
    {
        std::cout << "fopen error!" << std::endl;
        return;
    }
    fputs(message.c_str(),fd);
    fputs("\n",fd);
    fclose(fd);
}